package com.skirmisher.video.aliVideo.record;

import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vs.model.v20181212.*;
import com.skirmisher.video.aliVideo.BaseAliVideo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AliRecord
 * @Description TODO
 * @Author hanwangxin
 * @Date 2020/11/8 1:38 下午
 * @Version 1.0
 */
@Service
public class AliRecord extends BaseAliVideo {

    /**
     * @Author hanwangxin
     * @Description //TODO 截图 * @Date 2:03 下午 2020/11/8
     * @Param [streamId]
     * @return void
     **/
    public CreateStreamSnapshotResponse createStreamSnapshot(String streamId) throws ClientException {
        IAcsClient client = getClient();


        CreateStreamSnapshotRequest request = new CreateStreamSnapshotRequest();
        request.setId(streamId);

        CreateStreamSnapshotResponse acsResponse = client.getAcsResponse(request);
        
        return acsResponse;

    }

    /**
     * @Author hanwangxin
     * @Description //TODO 获取录制与截图信息 * @Date 1:43 下午 2020/11/8
     * @Param [type, steamId, startTime, endTime]
     * @return java.util.List<com.aliyuncs.vs.model.v20181212.DescribeRecordsResponse.Record>
     **/
    public List<DescribeRecordsResponse.Record> describeRecords(String type, String steamId, String startTime, String endTime) throws ClientException {

        IAcsClient client = getClient();

        DescribeRecordsRequest request = new DescribeRecordsRequest();

        request.setStreamId(steamId);
        request.setType(type);
        request.setStartTime(startTime);
        request.setEndTime(endTime);

        DescribeRecordsResponse acsResponse = client.getAcsResponse(request);

        return acsResponse.getRecords();

    }

    /**
     * @Author hanwangxin
     * @Description //TODO 开始录像 * @Date 2:00 下午 2020/11/8
     * @Param [streamId]
     * @return void
     **/
    public void startRecordStream(String streamId) throws ClientException {
        IAcsClient client = getClient();

        StartRecordStreamRequest request = new StartRecordStreamRequest();

        request.setId(streamId);

        client.getAcsResponse(request);

    }

    /**
     * @Author hanwangxin
     * @Description //TODO 结束录像 * @Date 2:02 下午 2020/11/8
     * @Param [streamId]
     * @return void
     **/
    public void stopRecordStream(String streamId) throws ClientException {
        IAcsClient client = getClient();

        StopRecordStreamRequest request = new StopRecordStreamRequest();
        request.setId(streamId);

        client.getAcsResponse(request);
    }
}
